<template>
	<div class="add-agent">
		<div>
			<label>{{ $t('route.base') }}</label>
			<div></div>
			<button><img /><label>{{ $t('route.Add_agent') }}</label></button>
		</div>
		<div>
			<el-form ref="form" label-width="100px">
				<el-form label-width="100px">
					<el-form-item :label="$t('route.Factory_ID')">
						<el-input :disabled="form.id != null" v-model="form.number" style="width:400px"></el-input>
					</el-form-item>
					<el-form-item :label="$t('route.Factory_Name')">
						<el-input v-model="form.name" style="width:400px"></el-input>
					</el-form-item>
					<el-form-item :label="$t('route.Factory_Address')">
						<el-cascader :options="areaSelectData" @change="handleChange" size="mini"
							v-model="form.selectedOptions" :placeholder="$t('route.Chose1')" />
						<el-input v-model="form.address" style="width:400px"></el-input>
					</el-form-item>
					<el-form-item :label="$t('route.Contact_Name')">
						<el-input v-model="form.contactName" style="width:400px"></el-input>
					</el-form-item>
					<el-form-item :label="$t('route.Telephone')">
						<el-input v-model="form.contactMobile" style="width:400px"></el-input>
					</el-form-item>
					<!-- <el-form-item label="区域">
						<el-select v-model="form.region" placeholder="请选择">
							<el-option v-for="item in  " :key="item.value" :label="item.label"
								:value="item.value"></el-option>
						</el-select>
						<el-button type="primary" style="margin-left:10px" @click="regionMgrClick">区域管理</el-button>
					</el-form-item> -->
					<el-form-item size="large">
						<el-button type="primary" @click="addClick">{{ $t('route.Add') }}</el-button>
					</el-form-item>
				</el-form>
			</el-form>
		</div>

	</div>
</template>

<script>
import http from "../../js/http/http.js";
import api from "../../js/http/api.js";
import CommonUtils from "../../js/common/common-utils.js";
import i18n from '../../i18n/index';
import { regionData, CodeToText, TextToCode } from "element-china-area-data";

export default {
	data() {
		return {
			form: {
				number: null,
				name: null,
				address: null,
				contactName: null,
				contactMobile: null,
				region: null,
			},
			regionList: [],
			areaSelectData: regionData,//省市区三级联动数据

		};
	},
	methods: {
		getAllRegion() {
			http.post(
				api.GET_ALL_REGION, {
				adminId: this.$store.state.user.id,
			},
				data => {
					this.regionList = data.data;
				}
			);
		},
		addClick() {
			if (CommonUtils.isEmpty(this.form.number)) {
				this.$message.error(i18n.global.t('route.Customer_ID_cannot_be_empty'));
				return;
			}
			if (CommonUtils.isEmpty(this.form.name)) {
				this.$message.error(i18n.global.t('route.Customer_name_cannot_be_empty'));
				return;
			}
			if (CommonUtils.isEmpty(this.form.address)) {
				this.$message.error(i18n.global.t('route.Address_cannot_be_empty'));
				return;
			}
			if (CommonUtils.isEmpty(this.form.contactName)) {
				this.$message.error(i18n.global.t('route.Contact_name_cannot_be_empty'));
				return;
			}
			if (CommonUtils.isEmpty(this.form.contactMobile)) {
				this.$message.error(i18n.global.t('route.Contact_number_cannot_be_empty'));
				return;
			}
			// if (CommonUtils.isEmpty(this.form.region)) {
			// 	this.$message.error("区域不能为空");
			// 	return;
			// }
			this.addCustomer();
		},
		addCustomer() {
			http.post(api.ADD_CUSTOMER, {
				adminId: this.$store.state.user.id,
				number: this.form.number,
				name: this.form.name,
				address: this.form.address,
				contactName: this.form.contactName,
				contactMobile: this.form.contactMobile,
				// region: this.form.region,
			}, data => {
				this.$message.success(i18n.global.t('route.Successfully_added'));
				this.form = {};
			});
		}
	},
	created() {
		this.getAllRegion();
	}
};
</script>
<style lang="scss" scoped>
.add-agent {
	color: #444444;
	font-size: 18px;
	padding-right: 20px;
	height: calc(100vh - 100px);
	// overflow: scroll;
	scrollbar-width: none;
	/* firefox */
	-ms-overflow-style: none;
	/* IE 10+ */
	overflow-x: hidden;
	overflow-y: auto;


	>div:nth-of-type(1) {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;

		>label:nth-of-type(1) {
			font-weight: 600;
		}

		>div:nth-of-type(1) {
			width: 1px;
			background-color: #cccccc;
			height: 15px;
			margin: 0px 20px;
		}

		>button:nth-of-type(1) {
			background-image: url(../../assets/img/customer-1.png);
			background-repeat: no-repeat;
			background-size: 100% 100%;
			padding: 5px 10px;
			border: 0px;
			display: flex;
			color: #ffffff;
			flex-direction: row;
			align-items: center;
			font-weight: 800;

			>img {
				margin-right: 7px;
				width: 15px;
				height: 15px;
				content: url(../../assets/img/customer-2.png);
			}

		}
	}

	>div:nth-of-type(2) {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin-top: 20px;
		background-color: #ffffff;
		padding: 20px;
		border-radius: 5px;

		.input {}

		.div-1 {
			display: flex;
			flex-direction: row;

			>label {
				margin-left: 10px;
				width: 200px;
			}
		}


	}





}
</style>
